package com.java.comprehensive.arithmetic.leecode.easy;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @program: comprehensive-service
 *
 * @description: 删除有序数组中的重复项
 *
 * @author: 窦绍飞
 *
 * @create: 2021-11-11 16:51
 **/
public class LeetCode_26 {

	private static class Solution {
		public static int removeDuplicates(int[] nums) {
			if (nums.length == 0) return 0;
			int i = 0;
			for (int j = 1; j < nums.length; j++) {
				//核心就是 把前面的排好序 后面乱的不用管
				//然后对比把不一样的放到前面排好
				if (nums[j] != nums[i]) {
					i++;
					nums[i] = nums[j];
				}
			}
			return i + 1;
		}

		public static void main(String[] args) {
			int[] nums = { 1, 1, 2 };
			int i = removeDuplicates(nums);
			System.out.println(i);
		}
	}

}
